<template>
	<el-header style="height: auto;">
		<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
	</el-header>
	<el-header>
		<div class="left-panel">
		</div>
		<div class="right-panel">
			<el-form-item label="发起人" style="padding-top: 20px;">
				<select-user-dialog v-model:accountId="search.createUser" :mode="false"/>
			</el-form-item>
			<div class="right-panel-search" style="width: auto;">
				<el-input v-model="search.bpmRunNo" placeholder="流水号" clearable></el-input>
				<el-input v-model="search.keyword" placeholder="流程标题" clearable></el-input>
				<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				<el-button type="danger" icon="el-icon-search" @click="advSearch">高级查询</el-button>
			</div>
		</div>
	</el-header>
	<el-main class="nopadding">
		<scTable ref="table" :params="{model:'0'}" :apiObj="list.apiObj" row-key="id" stripe>
			<el-table-column label="流水号" prop="id" width="80"></el-table-column>
			<el-table-column label="流程标题" prop="flowTitle" width="400"></el-table-column>
			<el-table-column label="参与人" prop="opUserStr" width="300" align="center" :show-overflow-tooltip="true"></el-table-column>
			<el-table-column label="紧急程度" prop="urgency" width="100" align="center">
				<template #default="scope">
					<el-tag v-if="scope.row.urgency==0" type="success">一般</el-tag>
					<el-tag v-else-if="scope.row.urgency==1" type="warning">紧急</el-tag>
					<el-tag v-else-if="scope.row.urgency==2" type="danger">加急</el-tag>
					<el-tag v-else type="info">未知</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="创建人" prop="createUser" width="100" align="center"></el-table-column>
			<el-table-column label="创建时间" prop="createTime" width="150" align="center"></el-table-column>
			<el-table-column label="状态" prop="status" width="150" align="center">
				<template #default="scope">
					<el-tag v-if="scope.row.status==0" type="success">进行中</el-tag>
					<el-tag v-else-if="scope.row.status==1" type="warning">已结束</el-tag>
					<el-tag v-else type="info">未知</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="操作" fixed="right" align="right" width="180">
				<template #default="scope">
					<el-button-group>
						<el-button text type="primary" size="small" @click="showBpmFlow(scope.row, scope.$index)">流程图</el-button>
						<el-button text type="primary" size="small" @click="readBpmDetails(scope.row,scope.$index)">查看</el-button>
						<el-button text type="primary" size="small" @click="printBpm(scope.row, scope.$index)" v-if="scope.row.printFlag==='1'">打印</el-button>
					</el-button-group>
				</template>
			</el-table-column>
		</scTable>
	</el-main>
</template>
<script>
import scSelectFilter from '@/components/scSelectFilter'
import selectUserDialog from "@/views/module/selectUserDialog";

export default {
	name: 'Bpm End',
	components: {
		scSelectFilter,
		selectUserDialog
	},
	data() {
		return {
			filterData: [{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},{
					title: "是否归档",
					key: "sealedStatus",
					multiple: false,
					options: [
						{
						label: "未归档",
						value: "0"
						},{
							label: "已归档",
							value: "1"
						}
						]
				},{
					title: "流程状态",
					key: "status",
					multiple: false,
					options: [{label: "全部", value: ""},{label: "过程中",value: "0"},{label: "已结束", value: "1"}]
				},
				{
					title: "流程分类",
					key: "flowId",
					multiple: true,
					options: [{
						label: "全部",
						value: ""
					}]
				},
				{
					title: "查询范围",
					key: "manageRole",
					multiple: false,
					options: [{
						label: "全部",
						value: "0"
						},
						{
							label: "我经办的",
							value: "1"
						},{
							label: "可查询的",
							value: "2"
						}]
				},
			],
			list: {
				apiObj: this.$API.bpm.bpmList.searchBpmList
			},
			search: {
				date:'',
				sealedStatus:'',
				status:'',
				flowId:'',
				keyword: "",
				bpmRunNo: '',
				model:'0',
				manageRole:'0',
				createUser: '',
			}
		}
	},
	mounted() {
		this.getBpmFlowListForSearch();
	},
	methods: {
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data) {
			this.search.date = data.date;
			this.search.sealedStatus = data.sealedStatus;
			this.search.status = data.status;
			this.search.flowId = data.flowId;
			this.search.manageRole = data.manageRole;
			this.$refs.table.upData(this.search)
		},
		async getBpmFlowListForSearch() {
			var res = await this.$API.bpm.bpmFlow.getBpmFlowListForSearch.get({model:'0'});
			if (res.code == 200) {
				this.filterData[3].options = this.filterData[3].options.concat(res.data)
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		advSearch() {
			this.$nextTick(() => {
				this.$router.replace({
					path: '/bpm/query/advancedquery',
				})
			})
		},
		showBpmFlow(row,index)
		{
			this.$nextTick(() => {
				this.$router.replace({
					path: '/bpm/setting/bpmflow/flowchartrun',
					query: {
						flowId: row.flowId,
						runId:row.runId
					}
				})
			})
		},
		printBpm(row,index)
		{
			this.$nextTick(() => {
				window.open('/#/bpm/handle/print?runId=' + row.runId+"&ddtab=true", "_blank");
			})
		},
		readBpmDetails(row,index)
		{
			this.$nextTick(() => {
				this.$router.replace({
					path: '/bpm/handle/read',
					query: {
						runId: row.runId
					}
				})
			})
		},
	}
}
</script>
